<template>
    <van-nav-bar v-show="isUserAgent" :title="title" :right-text="rigText" @click-right="onClickRight">
        <template #left>
            <van-icon name="cross" size="24" @click="toIndex"/>
        </template>
    </van-nav-bar>
</template>
<script>
import * as dd from 'dingtalk-jsapi';

export default {
    props: ["title", "backTru", "rigText"],
    name: "blockIndexNavBar",
    data: function () {
        return {
            isUserAgent: false,
        }
    },
    mounted() {
        this.$nextTick(() => {
            if (process.env.VUE_APP_MODE == 'mobile') {
                this.isUserAgent = false
            }
        })
        let that = this;
        // console.log("process.env.VUE_USER_AGENTprocess.env.VUE_USER_AGENT", process.env.VUE_USER_AGENT)
        // console.log("VUE_APP_MODEVUE_APP_MODEVUE_APP_MODE", process.env.VUE_APP_MODE)
        // if (process.env.VUE_USER_AGENT === 'dingTalk') {
        //     console.log("process.env.VUE_USER_AGENT", process.env.VUE_USER_AGENT)
        if (process.env.VUE_APP_MODE == 'mobile') {
            dd.ready(function () {
                dd.biz.navigation.setTitle({
                    title: that.title
                });
                dd.biz.navigation.setMenu({
                    textColor: "#ADD8E611",
                    items: [
                        {
                            "id": "exit",
                            "text": "首页",
                            "url": require("../assets/logout.png")
                        },
                        {
                            "id": "refresh",
                            "text": "刷新",
                            "url": require("../assets/refresh.png")
                        }
                    ],
                    onSuccess: function (data) {
                        if (data.id == 'exit') {
                            that.toIndex();
                        } else if (data.id == 'refresh') {
                            that.refresh();
                        }
                    }
                });
            });
        } else {
            this.isUserAgent = true;
        }
    },
    methods: {
        onClickRight() {
            this.$emit("rightTextClick")
        },
        toIndex() {
            if (typeof this.backTru != "undefined") {
                this.$emit("backMethod")
            } else {
                this.$router.go(-1)
            }
        },
        refresh() {
            location.reload();
        }
    }
}
</script>
